/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.jalarbee.liquid.security.service.impl;

import com.jalarbee.liquid.security.service.SecurityContextService;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 *
 * @author Abdoul
 */
@Named(value="securityContextService")
public class SpringSecurityUserContextServiceImpl implements SecurityContextService {

    private static final Logger logger = LoggerFactory.getLogger(SpringSecurityUserContextServiceImpl.class);
            
    public String getUsername() {
        try {
            return SecurityContextHolder.getContext().getAuthentication().getName();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

}
